<template>
    <el-dialog title="用户详情" :visible.sync="visible" width="850px" :before-close="handleClose">
        <el-form ref="form" :model="form" label-width="100px">
            <el-row>
                <el-col :span="16">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="用户姓名" prop="personnelName">
                                <el-input disabled class="input180" v-model="form.personnelName" placeholder="请输入用户昵称"
                                    maxlength="100" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="性别" prop="gender">
                                <el-select disabled class="input180" v-model="form.gender" placeholder="请选择性别">
                                    <el-option label="男" :value="1"></el-option>
                                    <el-option label="女" :value="2"></el-option>
                                    <el-option label="未知" :value="0"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="年龄" prop="age">
                                <el-input disabled class="input180" v-if="form.age && form.age>0" v-model="form.age" type="number" placeholder="请输入年龄"
                                    maxlength="11" />
                                    <span v-else> -</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="出生日期" prop="dateOfBirth">
                                <el-date-picker disabled type="month" value-format="yyyy-MM" v-model="form.dateOfBirth"
                                    class="input180"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="籍贯" prop="jiguan">
                                <el-cascader disabled v-model="form.jiguan" class="input180" :options="chinaLocations"
                                    placeholder="请选择省市区" clearable></el-cascader>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="详细地址" prop="birthplaceAddress">
                                <el-input disabled v-model="form.birthplaceAddress" class="input180" placeholder="请输入详细地址"
                                    maxlength="90" />
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :span="12">
                            <el-form-item label="军人证件号" prop="personnelUnitNum">
                                <el-input disabled v-model="form.personnelUnitNum" class="input180" placeholder="请输入编号" />
                            </el-form-item>
                        </el-col> -->
                        <el-col :span="12">
                            <el-form-item label="政治面貌" prop="politicalStatus">
                                <el-select disabled class="input180" v-model="form.politicalStatus" placeholder="请选择政治面貌">
                                    <el-option label="群众" :value="1"></el-option>
                                    <el-option label="团员" :value="2"></el-option>
                                    <el-option label="党员" :value="3"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-col>

                <el-col :span="8">
                    <el-form-item label="照片" prop="personnelPic">
                        <div style="width: 120px;height: 135px;overflow: hidden;">
                            <img style="display: block;width: 100%;" v-if="form.personnelPic" :src="downloadUrl + form.personnelPic"
                                alt="">
                            <img style="display: block;width: 100%;" v-else src="../assets/images/avatar.png" alt="">
                        </div>

                    </el-form-item>
                </el-col>

                <el-col :span="8">
                    <el-form-item label="身份证号码" prop="idCardNo">
                        <el-input disabled v-model="form.idCardNo" class="input180" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="警衔" prop="policeRankCode">
                        <el-select disabled v-model="form.policeRankCode" placeholder="请选择" clearable filterable
                            class="input180">
                            <el-option v-for="dict in dict.type.sys_police_rank_code" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="职务" prop="positionCode">
                        <el-select disabled v-model="form.positionCode" placeholder="请选择" clearable filterable
                            class="input180">
                            <el-option v-for="dict in dict.type.sys_position_code" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                </el-col>

                <el-col :span="8">

                    <el-form-item label="专业" prop="majorCode">
                        <el-select disabled v-model="form.majorCode" placeholder="请选择" clearable filterable
                            class="input180">
                            <el-option v-for="dict in dict.type.sys_user_major_code" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="在位状态" prop="workingStatus">
                        <el-select disabled v-model="form.workingStatus" placeholder="请选择" clearable filterable
                            class="input180">
                            <el-option v-for="dict in dict.type.sys_user_staff_status" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="军籍状态" prop="militaryStatus">
                        <el-select disabled class="input180" v-model="form.militaryStatus" placeholder="请选择军籍状态">
                            <el-option label="在籍" :value="1"></el-option>
                            <el-option label="退役" :value="2"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="血型" prop="bloodType">
                        <el-select disabled v-model="form.bloodType" placeholder="请选择" clearable filterable
                            class="input180">
                            <el-option v-for="dict in dict.type.sys_user_blood_type" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                </el-col>

                <el-col :span="8">
                    <el-form-item label="入伍时间" prop="enlistmentTime">
                        <el-date-picker disabled v-model="form.enlistmentTime" value-format="yyyy-MM" type="month"
                            class="input180"></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="归属单位" prop="unitCode">
                        {{ form.unitLabelPath }}
                    </el-form-item>
                </el-col>
                <el-col :span="16">
                    <el-form-item label="毕业院校" prop="graduatedSchool">
                        <el-input disabled class="input180" v-model="form.graduatedSchool" placeholder="请输入毕业院校" />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="个人特长" prop="specialties">
                        <el-input disabled type="textarea" v-model="form.specialties" placeholder="请输入个人特长" />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="奖惩情况" prop="rewardsAndPunishments">
                        <el-input disabled type="textarea" v-model="form.rewardsAndPunishments" placeholder="请输入奖惩情况" />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-tabs>
                        <el-tab-pane label="任职经历">
                            <el-input type="textarea" disabled :rows="6" v-model="form.mainExperience" placeholder="请输入"
                                clearable />
                        </el-tab-pane>
                        <el-tab-pane label="培训、学习、重大任务经历">
                            <el-input type="textarea" disabled :rows="6" v-model="form.otherMainExperience"
                                placeholder="请输入" clearable />
                        </el-tab-pane>

                    </el-tabs>
                </el-col>
            </el-row>
        </el-form>
    </el-dialog>
</template>
    
<script>
import { deptTree } from "@/api/org";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { roleOptionSelect } from "@/api/role";
import { getUserProfile } from '@/api/system/user'
import provinceJson from "./province.json";
import { util } from 'echarts';
export default {
    dicts: ['sys_police_rank_code', 'sys_user_staff_status', 'sys_position_code', 'sys_user_blood_type', 'sys_user_major_code'],
    props: {
        visible: {
            default: false,
            type: Boolean
        },
        id: {
            default: false,
            type: String
        }
    },
    data() {
        return {
            chinaLocations: provinceJson, //省市区json
            fileList: [],
            deptOptions: [],
            roleList: [],
            form: {}
        }
    },
    computed: {
        downloadUrl() {
            return process.env.VUE_APP_DOWNLOAD_URL
        },
        deptList() {
            return this.$store.state.user.deptList
        },
    },
    watch: {
        visible(val) {
            if (val) {
                this.getUserInfo();
            }
        }
    },
    created() {
        this.getRoleList();
        this.getDeptTree();
    },
    components: {
        Treeselect
    },
    methods: {
        findLabelById(data, targetId, path = []) {
            for (const item of data) {
                const currentPath = [...path, item.label];
                if (item.id == targetId) {
                    return currentPath.join('/');
                }
                if (item.children) {
                    const found = this.findLabelById(item.children, targetId, currentPath);
                    if (found) {
                        return found;
                    }
                }
            }
            return '';
        },
        /** 查询单位下拉树结构 */
        getDeptTree() {
            deptTree().then(response => {
                this.deptOptions = response.data;
            });
        },
        async getRoleList() {
            const res = await roleOptionSelect()
            if (res.code === 200) {
                let tmpList = res.data
                this.roleList = tmpList.filter(item => {
                    return item.roleKey !== 'common'
                })
            }
        },
        // 关闭弹窗
        handleClose() {
            this.$emit('update:visible', false);
        },
        // 获取用户信息
        async getUserInfo() {
            getUserProfile(this.id).then(response => {
                response.data.bloodType = String(response.data.bloodType)
                response.data.workingStatus = String(response.data.workingStatus)
                this.form = response.data;
                this.form.unitCode = String(this.form.unitCode)
                this.form.unitLabelPath = this.findLabelById(this.deptOptions, this.form.unitCode);
                if (response.data.provinceCode) {
                    this.form.jiguan = [response.data.provinceCode, response.data.cityCode, response.data.areaCode]
                }
            });
        }
    }
};
</script>
<style>
.input180 {
    display: block;
    width: 170px !important;
}
</style>
    